package com.ctcemti.mdm.project.sys.controller;


import com.ctcemti.mdm.common.result.Result;
import com.ctcemti.mdm.common.result.ResultEnum;
import com.ctcemti.mdm.project.sys.entity.ErrorLog;
import com.ctcemti.mdm.project.sys.service.IErrorLogService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 错误日志Controller
 * 
 * @author 
 * @date Tue Nov 12 08:15:44 CST 2019
 */
@Controller
@Api(value = "ErrorLogController", description = "错误日志控制器类")
@RequestMapping("/system/errorlog")
public class ErrorLogController
{

    @Autowired
    private IErrorLogService errorLogService;

    /**
     * 查询错误日志对象
     */
    @PostMapping("/query")
    @ResponseBody
    public Result<ErrorLog> query(HttpServletRequest request, HttpServletResponse response ,Integer id)
    {
        ErrorLog errorLog = errorLogService.selectErrorLogById(id);
        return new Result<ErrorLog>(ResultEnum.SUCCESS,errorLog);
    }

    /**
     * 查询错误日志列表
     */
    @PostMapping("/list")
    @ResponseBody
    public Result<PageInfo<ErrorLog>> queryList(HttpServletRequest request, HttpServletResponse response ,ErrorLog errorLog)
    {
        PageInfo<ErrorLog> pageInfo = errorLogService.selectErrorLogList(errorLog);
        return new Result<PageInfo<ErrorLog>>(ResultEnum.SUCCESS,pageInfo);
    }



    /**
     * 新增保存错误日志
     */
    @PostMapping("/add")
    @ResponseBody
    public Result<ErrorLog> insertErrorLog(HttpServletRequest request, HttpServletResponse response ,ErrorLog errorLog)
    {
         errorLogService.insertErrorLog(errorLog);
         return new Result<ErrorLog>(ResultEnum.SUCCESS,null);
    }

    /**
     * 修改错误日志
     */
    @PostMapping("/update")
    @ResponseBody
    public Result<ErrorLog> updateErrorLog(HttpServletRequest request, HttpServletResponse response,  ErrorLog errorLog)
    {
        errorLogService.updateErrorLog(errorLog);
        return new Result<ErrorLog>(ResultEnum.SUCCESS,null);
    }


    /**
     * 删除错误日志
     */
    @PostMapping("/delete")
    @ResponseBody
    public Result<ErrorLog> remove(HttpServletRequest request, HttpServletResponse response ,String ids)
    {
        errorLogService.deleteErrorLogByIds(ids);
        return new Result<ErrorLog>(ResultEnum.SUCCESS,null);
    }

    @PostMapping("/common/download/downWorkbook")
    public void downWorkbook(HttpServletRequest request, HttpServletResponse response,String filename) throws Exception {
        errorLogService.uploadFile(response,request,filename);

    }

}
